# 设置Django运行所依赖的环境变量
import os
if not os.environ.get('DJANGO_SETTINGS_MODULE'):
  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'meiduo_mall.settings.dev')

# 让Django进行一次初始化
import django
django.setup()

from django.core.files import File
from goods.models import SKUImage
if __name__ == '__main__':
    file = open('/home/ubuntu/Desktop/1.jpg', 'rb')
    file = File(file)

    # 保存文件
    # SKUImage.objects.create(image=file, sku_id=5)
    sku_image = SKUImage.objects.get(id=43)
    sku_image.image = file
    sku_image.save()
